package com.shujia.zookeeper;

import org.apache.zookeeper.*;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

public class ZKWacher {
    ZooKeeper zooKeeper;
    @Before
    public void init() throws Exception {
         zooKeeper = new ZooKeeper ("master:2181,node1:2181,node2:2181", 3000, null);

    }
    @Test
    public void create() throws KeeperException, InterruptedException {
        zooKeeper.create ("/test01", "test".getBytes ( ), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    }
    @Test
    public void children() throws KeeperException, InterruptedException {
        zooKeeper.getChildren ("/test01", new Watcher ( ) {

            public void process(WatchedEvent watchedEvent) {
                System.out.println ("当前节点不存在" );
            }
        });
        while(true){}
    }

}
